function UserInfoCtrl($scope, $state, $http, Data) {	
	$scope.user = {};
	$http({
		url: 'user/getCurrentUser',
		method: 'get'
			}).success(function(response) {
				$scope.user = response;
				$scope.user.cardId = parseInt(response.cardId);
				console.log(response);
			})
    $scope.save = function() {
		console.log($scope.user);
        Data.set($scope.user);
        $('#sure').modal();
    }
    $scope.submits = function(val) {
        if (val == "save") {
            $scope.user = Data.get();
            console.log($scope.user);
        	$http({
        		url: 'user/update',
        		method: 'post',
				params: {
					realName: $scope.user.realName,
					grade: $scope.user.grade,
					gender: $scope.user.gender,
					institute: $scope.user.institute,
					cardId: $scope.user.cardId,
					photoUrl: $scope.user.photoUrl
				}
			}).success(function(response) {
                $('.close').click();
				$state.go('index.userInfo', {reload: true});
			})
        } else {
            $('.close').click();
        }
    }
}

function ChangePasswordCtrl($scope, $state, $http, Data) {	
	
	$scope.isPasswordRight=false;
	$scope.isPasswordWrong=false;
	$scope.isRetypeSame=false;
	$scope.isRetypeDiff=false;
	$scope.isPasswordRight=function(){
        $http({
            url:'user/isPasswordRight',
            method:'post',
            params:{
                password:$scope.oldPassword
            }
        }).success(function(response){
        	console.log(response);
            if(response=="Y"){
                $scope.isPasswordWrong=false;
            }else{
                $scope.isPasswordWrong=true;
            }
        })
    }
	$scope.isRetypeSame=function(){
        if($scope.retypePassword==$scope.newPassword){
        	$scope.isRetypeDiff=false;
        }else{
        	$scope.isRetypeDiff=true;
        }
    }
	
	$scope.user = {};
	$http({
		url: 'user/getCurrentUser',
		method: 'get'
			}).success(function(response) {
				$scope.user = response;
			})
    $scope.save = function() {
		console.log($scope.user);
        Data.set($scope.user);
        $('#sure').modal();
    }
    $scope.submits = function(val) {
        if (val == "save") {
            $scope.user = Data.get();
            
        	$http({
        		url: 'user/resetPassword',
        		method: 'post',
				params: {
					password: $scope.newPassword,
				}
			}).success(function(response) {
                $('.close').click();
				$state.go('index.userInfo', {reload: true});
			})
        } else {
            $('.close').click();
        }
    }
}